﻿using System;
using System.Collections.ObjectModel;
using Mal.Balades.Admin.Services;
using System.Linq;
using System.Collections.Generic;
using Mal.Balades.Admin.Repositories;

namespace Mal.Balades.Admin.ViewModels.VisitViewModels.Edit
{
    public class VisitViewModel : DataViewModelBase
    {
        #region Fields
        IVisitAdmin _visit;
        private int? visitID;
        private string title;
        private bool qualitySumUp;
        private bool qualityText;
        private bool qualityGps;
        private bool qualityPictures;
        private bool qualityInformations;
        private bool qualityCategories;
        private int? placeCategoryID;
        private int? marketingCategoryID;
        private string urlName;
        private string sumUp;
        private string text;
        // private DateTime? creationDate;
        private double? latitude;
        private double? longitude;
        private bool visible;

        ObservableCollection<InformationViewModel> informations = new ObservableCollection<InformationViewModel>();
        ObservableCollection<PictureViewModel> pictures = new ObservableCollection<PictureViewModel>();

        private ObservableCollection<ICategory> placeCategories;
        private ICategory selectedPlaceCategory;

        private ObservableCollection<ICategory> marketingCategories;
        private ICategory selectedMarketingCategory;



        #endregion

        #region Construction / Destruction
        public VisitViewModel()
        {
            Initialize();
        }

        public VisitViewModel(IVisitAdmin visit)
            : this()
        {
            this.Visit = visit;
        }
        #endregion

        #region enum, struct, class
        public class Category
        {
            public int CategoryID { get; set; }
            public string Text { get; set; }
            public string ImageUrl { get; set; }
        }
        #endregion

        #region Properties
        private IVisitAdmin Visit
        {
            get { return _visit; }
            set
            {
                _visit = value;
                //RaisePropertyChanged("Visit");

                this.Latitude = _visit.Latitude;
                this.Longitude = _visit.Longitude;
                this.MarketingCategoryID = _visit.MarketingCategoryID;
                this.PlaceCategoryID = _visit.PlaceCategoryID;
                this.QualityCategories = _visit.QualityCategories;
                this.QualityGps = _visit.QualityGps;
                this.QualityInformations = _visit.QualityInformations;
                this.QualityPictures = _visit.QualityPictures;
                this.QualitySumUp = _visit.QualitySumUp;
                this.QualityText = _visit.QualityText;
                this.SumUp = _visit.SumUp;
                this.Text = _visit.Text;
                this.Title = _visit.Title;
                this.UrlName = _visit.UrlName;
                this.Visible = _visit.Visible;
                this.VisitID = _visit.VisitID;

            }
        }

        public ObservableCollection<InformationViewModel> Informations
        {
            get { return informations; }
            set
            {
                informations = value;
                RaisePropertyChanged("Informations");
            }
        }

        public Double? Latitude
        {
            get { return this.latitude; }
            set
            {
                latitude = value;
                RaisePropertyChanged("Latitude");
            }
        }

        public Double? Longitude
        {
            get { return longitude; }
            set
            {
                longitude = value;
                RaisePropertyChanged("Longitude");
            }
        }

        public ObservableCollection<PictureViewModel> Pictures
        {
            get { return pictures; }
            set
            {
                pictures = value;
                RaisePropertyChanged("Pictures");
            }
        }

        public Int32? PlaceCategoryID
        {
            get { return placeCategoryID; }
            set
            {
                if (placeCategoryID != value)
                {
                    placeCategoryID = value;
                    RaisePropertyChanged("PlaceCategoryID");

                    ICategory category = PlaceCategories.FirstOrDefault(c => c.CategoryID == placeCategoryID);

                    if (category != null)
                        this.SelectedPlaceCategory = category;

                }
            }
        }

        public ICategory SelectedPlaceCategory
        {
            get { return selectedPlaceCategory; }
            set
            {
                if (selectedPlaceCategory != value)
                {
                    selectedPlaceCategory = value;
                    RaisePropertyChanged("SelectedPlaceCategory");

                    if (selectedPlaceCategory != null)
                        this.PlaceCategoryID = selectedPlaceCategory.CategoryID;
                }
            }
        }

        public ObservableCollection<ICategory> PlaceCategories
        {
            get { return placeCategories; }
            set
            {
                if (placeCategories != value)
                {
                    placeCategories = value;
                    RaisePropertyChanged("PlaceCategories");
                }
            }
        }

        public Int32? MarketingCategoryID
        {
            get { return marketingCategoryID; }
            set
            {
                if (marketingCategoryID != value)
                {
                    marketingCategoryID = value;
                    RaisePropertyChanged("MarketingCategoryID");
                    ICategory category = MarketingCategories.FirstOrDefault(c => c.CategoryID == marketingCategoryID);

                    if (category != null)
                        this.SelectedMarketingCategory = category;
                }
            }
        }

        public ICategory SelectedMarketingCategory
        {
            get { return selectedMarketingCategory; }
            set
            {
                if (selectedMarketingCategory != value)
                {
                    selectedMarketingCategory = value;
                    RaisePropertyChanged("SelectedMarketingCategory");
                    if (selectedMarketingCategory != null)
                        this.MarketingCategoryID = selectedMarketingCategory.CategoryID;
                }
            }
        }

        public ObservableCollection<ICategory> MarketingCategories
        {
            get { return marketingCategories; }
            set
            {
                if (marketingCategories != value)
                {
                    marketingCategories = value;
                    RaisePropertyChanged("MarketingCategories");
                }
            }
        }

        public String SumUp
        {
            get { return sumUp; }
            set
            {
                sumUp = value;
                RaisePropertyChanged("SumUp");
            }
        }

        public String Text
        {
            get { return text; }
            set
            {
                text = value;
                RaisePropertyChanged("Text");
            }
        }

        public String Title
        {
            get { return title; }
            set
            {
                title = value;
                RaisePropertyChanged("Title");

            }
        }

        public String UrlName
        {
            get { return urlName; }
            set
            {
                urlName = value;
                RaisePropertyChanged("UrlName");
            }
        }

        public Boolean Visible
        {
            get { return visible; }
            set
            {
                visible = value;
                RaisePropertyChanged("Visible");
            }
        }

        public int? VisitID
        {
            get { return visitID; }
            set
            {
                visitID = value;
                RaisePropertyChanged("VisitID");
            }
        }

        public bool QualitySumUp
        {
            get
            {
                return qualitySumUp;
            }
            set
            {
                qualitySumUp = value;
                RaisePropertyChanged("QualitySumUp");
            }
        }

        public bool QualityText
        {
            get
            {
                return qualityText;
            }
            set
            {
                qualityText = value;
                RaisePropertyChanged("QualityText");
            }
        }

        public bool QualityGps
        {
            get
            {
                return qualityGps;
            }
            set
            {
                qualityGps = value;
                RaisePropertyChanged("QualityGps");
            }
        }

        public bool QualityPictures
        {
            get
            {
                return qualityPictures;
            }
            set
            {
                qualityPictures = value;
                RaisePropertyChanged("QualityPictures");
            }
        }

        public bool QualityInformations
        {
            get
            {
                return qualityInformations;
            }
            set
            {
                qualityInformations = value;
                RaisePropertyChanged("QualityInformations");
            }
        }

        public bool QualityCategories
        {
            get
            {
                return qualityCategories;
            }
            set
            {
                qualityCategories = value;
                RaisePropertyChanged("QualityCategories");
            }
        }

        #endregion

        #region Methods
        protected override bool GetIsChanged()
        {
            return false;
        }

        private void Initialize()
        {
            this.PlaceCategories = new ObservableCollection<ICategory>();
            this.MarketingCategories = new ObservableCollection<ICategory>();

            foreach (ICategory category in Repository.Instance.Categories.Datas)
            {
                if (category.CategoryTypeID == 1)
                    this.PlaceCategories.Add(category);
                else if (category.CategoryTypeID == 2)
                    MarketingCategories.Add(category);
            }

        }
        #endregion

        #region Events

        #endregion

    }
}
